package com.hyw.supply.model.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author zzp
 * @date 2024/3/14 17:54
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageVO<T> implements Serializable {

    @Schema(title = "page", description = "当前页")
    private Long page;

    @Schema(title = "size", description = "每页数量")
    private Long size;

    @Schema(title = "totalPage", description = "总页数")
    private Long totalPage;

    @Schema(title = "totalCount", description = "总记录数")
    private Long totalCount;

    @Schema(title = "data", description = "数据集")
    private List<T> data;

    public PageVO(IPage<T> page) {
        this.page = page.getCurrent();
        this.size = page.getSize();
        this.totalPage = page.getPages();
        this.totalCount = page.getTotal();
        this.data = page.getRecords();
    }

    /**
     * 转换为page
     *
     * @param page
     * @param <T>
     * @return
     */
    public static <T> PageVO<T> convertPage(IPage<T> page) {
        return new PageVO(page);
    }

}
